﻿/**
  NELMATE   ELMATEC   LM      EL  TECONELMA  CO         NE          MA   ONELMAT    ELMATECO  LMATECONE 
 ON        NE     CO  LMA     EL  TE         CO         NEL        LMA  CO      EC     AT     LM       
CO         NE     CO  LMAT    EL  TE         CO         NELM      ELMA  CO      EC     AT     LM
CO         NE     CO  LM TE   EL  TECONELM   CO         NE MA    NE MA  CONELMATEC     AT     LMATECONE
CO         KC     CO  LM  EC  EL  TE         CO         NE  AT  ON  MA  CO      EC     AT     LM
 ON        KC     CO  LM   CO EL  TE         CO         NE   TECO   MA  CO      EC     AT     LM
  NELMATE   ELMATEC   LM    ONEL  TECONELMA  CONELMATE  NE    EC    MA  CO      EC     AT     LMATECONE
_______________________________________________________________________________________________________
 ConelMate Framework 3.0 - copyright 2007(c) Ruben Sainz de la Maza
 
	@class: 	Trace
	@vertion: 	0.1
	@date:		28/11/07
				
	@language: 	ActionScript 3.0
	@author:	Ruben Sainz de la Maza
	@usage: 
		import com.conelmate.util.Trace;
		package{
			class example extends Trace{
				function example(){
					_isTrace = true;
					mTrace("#Example# constructor");
				}
			}
		} 
		
**/

package com.conelmate.util
{

	import flash.display.Sprite;
	import flash.net.LocalConnection;
	import flash.events.StatusEvent;
	

	public class Trace extends Sprite
	{
	
				public  var _isTrace		:Boolean;			//hace trace de aquellas clases que seteen _isTrace = true;
		static	private	var _isALL			:Boolean = false;	//hace el trace independientemente de cualquier otro seteo
		static	private var _isINITIALIZED	:Boolean = false;	//si ya esta inicializado : true
		static	private var _LC 			:LocalConnection;	//ref a la clase LocalConnection
		static	private var _strCONN		:String;			//string de coneccion para LocalConnection
	
	
		/**
		 *	constructor
		 */
		public function Trace()
		{
			_strCONN = "_ConelmateDebug";
		}
	


		//-------------------------------------
		//   Public Methods
		//-------------------------------------

		/**
		 * enviar mensajes por trace
		 */
		public function mTrace(p:String) :void 
		{	
			outputTrace(p);		
			if (_isTrace || _isALL) trace(p);		
		}

		
		/**
		 *	crea un localconnection y envia los datos a la aplicación Debug.swf externa
		 */	
		public function outputTrace(p:String) :void 
		{
			if(!_isINITIALIZED){
				_isINITIALIZED = true;				
				_LC = new LocalConnection();
			}
			_LC.addEventListener(StatusEvent.STATUS, onStatus);
			_LC.send(_strCONN, "write", p);			
		}
		
		
		
		//-------------------------------------
		//   Private Methods
		//-------------------------------------
		
		/**
		 * status para saber si se concreto la coneccion y envido de datos
		 */		
        private function onStatus(event:StatusEvent):void {
			//sin implementar
        }
		
	}	
}